package zmee.pmas.form;

import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;

import java.math.BigDecimal;

/**
 * @author yss
 * @createTime 2022-12-13 1:20
 * @description 项目立项表单插件
 */
public class ProApprovalBillPluginEx extends AbstractBillPlugIn {

    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        String name = e.getProperty().getName();
        ChangeData changeData = e.getChangeSet()[0];
        Object newValue = changeData.getNewValue();
        Object oldValue = changeData.getOldValue();
        if("pro".equals(name)){//修改财务概算（元）字段 zmee_textfield1
            if(newValue != null){
                BigDecimal budgetNum = BigDecimal.ZERO;
                DynamicObject proDy = (DynamicObject) newValue;
                DynamicObject budgetDy = BusinessDataServiceHelper.loadSingleFromCache("zmee_project_budget", new QFilter[]{new QFilter("projectname", QCP.equals, proDy.getLong("id"))});
                if(budgetDy != null){
                    budgetNum = budgetDy.getBigDecimal("budgetnum");
                }
                getModel().setValue("zmee_textfield1",budgetNum);
            }
        }
    }
}
